package org.smart4j.chapter2.service;

import org.slf4j.Logger;
import org.smart4j.chapter2.helper.DatabaseHelper;
import org.smart4j.chapter2.model.Customer;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/11/20.
 */
public class CustomerService {
    private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CustomerService.class);
    public List<Customer> getCustomerList(){
        String sql = "select * from customer";
        return DatabaseHelper.queryEntityList(Customer.class, sql);
    }

    public Customer getCustomer(int id){
        String sql = "select * from customer where id =  ?";
        return DatabaseHelper.queryEntity(Customer.class,  sql, id);
    }

    public boolean createCustomer(Map<String, Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class, fieldMap);
    }

    public boolean updateCustomer(int id, Map<String, Object> fieldMap){
        return DatabaseHelper.updateEntity(Customer.class, fieldMap);
    }

    public boolean deleteCustomer(int id){
        return DatabaseHelper.deleteEntity(Customer.class, id);
    }
}
